package com.css.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.css.entity.DataGdp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Dbj
 * @date 2024年11月08日  10:35
 */
@Mapper
public interface DataGdpMapper extends BaseMapper<DataGdp> {
    @Select("select if(sum(economics) is null,0,sum(economics)) economics from data_gdp where ST_Intersects(geom, st_geometryfromtext(#{geom},#{code}))")
    List<DataGdp> getByGeom(@Param("geom")String intersectGeom, @Param("code")String code);

    @Select("WITH sjz AS ( SELECT ST_GeomFromText ( #{geom},#{code} ) AS geom ) SELECT if(SUM( ( P ).val ) is null,0,SUM( ( P ).val )) AS economics " +
            "FROM data_gdp_raster r JOIN sjz s ON ST_Intersects ( r.geom, s.geom ) CROSS JOIN LATERAL ST_PixelAsPolygons ( ST_Clip ( r.geom, s.geom ) ) AS P " +
            "WHERE ( P ).val >= 0")
    List<DataGdp> getByGeom1(@Param("geom")String intersectGeom, @Param("code")String code);
}
